
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <title>申请成为捎货人</title>
  <link rel="stylesheet" type="text/css" href="../css/api.css" />
  <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style type="text/css">
    .empty {
        text-align: center;
        padding-top: 40px;
    }
    .top{
    	width:100%;
    	height: 40px;
    	margin: 40px auto 0px;
    	background: #f5f5f5;
    	color:#000;
    	border:0px;
    	display: block;
    	text-align: center;
    }
    .leftreturn{
      position: absolute;
      left:0;
      z-index: 5;
      background-image: url("../../image/leftreturn.png");
      background-position: 0px 0px;
      width:25px;
      height:25px;
      margin:7.5px 0;
    }
    .top-title{
      line-height: 40px;
      font-size: 20px;
    }
.content{
	width:100%;
	height: 450px;
	margin-top: 20px;
	background: white;
	color:#000000;
	border:0px;
	display: block;
	font-size: 14px;
}
.content-cell{
	width:100%;
	height: 50px;
	margin: 10px auto 0px;
	background: white;
	color:#000000;
	border:0px;
	display: block;
	font-size: 17px;
}
.content-text{
	width:90%;
	height: 30px;
	margin: 0 auto;
	margin-top: 0;
	color:#000000;
	border:1px;
	border-style: solid;
	border-color: #999999;
	display: block;
	font-size: 14px;
}
.button {
	width:80%;
	height: 40px;
	margin: 0 auto;
	margin-top: 15px;
	background: #0082E4;
	color:#FFFFFF;
	font-size: 18px;
	border:0px;
	display: block;
}
    </style>
</head>
<body>
  <div class="empty">

      <div class="top">
        <i class="leftreturn"></i>
        <h1 class="top-title">申请成为捎货人</h1>
      </div>
    	<div class="content">
    			<li class="content-cell">
    				<label for="">真实姓名</label>
    				<input class="content-text" type="text" id="realname"/>
    			</li>
    			<li class="content-cell">
    				<label for="">身份证号码</label>
    				<input class="content-text" type="text" id="idcard"/>
    			</li>
    			<li class="content-cell">
    				<label for="">本人手机号</label>
    				<input class="content-text" type="text" id="mobile"/>
    			</li>

    			<li class="content-cell">
    				<label for="">紧急联系人姓名</label>
    				<input class="content-text" type="text" id="secondname"/>
    			</li>
    			<li class="content-cell">
    				<label for="">紧急联系人手机号码</label>
    				<input class="content-text" type="text" id="secondmobile"/>
    			</li>
    			<li class="content-cell">
    				<label for="">驾驶证号</label>
    				<input class="content-text" type="text" id="drivingid"/>
    			</li>
    			<li class="content-cell">
    				<label for="">车辆行驶证号</label>
    				<input class="content-text" type="text" id="roadworthy"/>
    			</li>
    			</div>

    		<button class="button" onclick="tiaozhuan_xiadanxuanze();">提 交</button>
    	</div>

</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/SHA1.js"></script>
<script type="text/javascript">
  function tiaozhuan_xiadanxuanze() {
  var  realname=document.getElementById('realname').value;
  var  idcard=document.getElementById('idcard').value;
  var  mobile=document.getElementById('mobile').value;
  var  secondname=document.getElementById('secondname').value;
  var  secondmobile=document.getElementById('secondmobile').value;
  var  drivingid=document.getElementById('drivingid').value;
  var  roadworthy=document.getElementById('roadworthy').value;
  var  user = $api.getStorage('user');
    var now = Date.now();
     appKey = SHA1("A6032422409194"+"UZ"+"808CF36B-60D4-DC5D-C9F3-FB49F9E1FB44"+"UZ"+now)+"."+now

     api.ajax({
         url: "https://d.apicloud.com/mcm/api/user/"+user[0].id+"/delivery",
         method: 'post',
         cache:  false,
         headers:{
           "X-APICloud-AppId": "A6032422409194",
           "X-APICloud-AppKey": appKey
         },
         data:{
           values: {
            "realname":realname,
           "idcard":idcard,
           "mobile":mobile,
           "secondname":secondname,
           "secondmobile":secondmobile,
           "drivingid":drivingid,
           "roadworthy":roadworthy
                   }
         }
     },function(ret, err){
         if (ret) {
             alert('注册捎货人成功');
             //将isdelivery设置为true
             api.ajax({
                 url: "https://d.apicloud.com/mcm/api/user/"+user[0].id,
                 method: 'post',
                 cache:  false,
                 headers:{
                   "X-APICloud-AppId": "A6032422409194",
                   "X-APICloud-AppKey": appKey
                 },
                 data:{
                   values: {
                    "isdelivery":true,
                    "_method":"PUT"
                           }
                 }
             },function(ret, err){
                 if (ret) {
                     user=$api.getStorage('user');
                     user[0].isdelivery=ret.isdelivery;
                     $api.setStorage('user',user);
                     api.closeWin({
                         name: api.winName
                     });

                 } else {
                   alert('数据库连接失败');
             }
             });

         } else {
             alert('数据库连接失败');
         }
     });


  }
</script>

</html>
